package com.zx.tv.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;

import com.zx.base.lazylist.ImageLoader;
import com.zx.tv.MusicReceiver;
import com.zx.tv.R;
import com.zx.tv.entity.Music;
import com.zx.tv.entity.Weather;

public class NewTVApp extends Application {

	public Music music = new Music();
	public ImageLoader imageloader;
	public Weather weather =new Weather();
	public Map<String, Object> weathermap = new HashMap<String, Object>(); // 登录时向服务器发送的参数
	@Override
	public void onCreate() {
		super.onCreate();
		imageloader=new ImageLoader(getApplicationContext());
		weathermap.put("", R.drawable.sunny);
		weathermap.put("sunny", R.drawable.sunny);
		weathermap.put("cloudy", R.drawable.cloudy);
		weathermap.put("overcast", R.drawable.overcast);
		weathermap.put("lrain", R.drawable.lrain);
		weathermap.put("mrain", R.drawable.mrain);
		weathermap.put("hrain", R.drawable.hrain);
		weathermap.put("train", R.drawable.train);
		weathermap.put("shower", R.drawable.shower);
		weathermap.put("tshower", R.drawable.shower);
		weathermap.put("lighting", R.drawable.lighting);
		weathermap.put("hail", R.drawable.hail);
		weathermap.put("lfog", R.drawable.fog);
		weathermap.put("fog", R.drawable.fog);
		weathermap.put("sfog", R.drawable.fog);
		weathermap.put("haze", R.drawable.fog);
		weathermap.put("sleet", R.drawable.sleet);
		weathermap.put("lsnow", R.drawable.lsnow);
		weathermap.put("msnow", R.drawable.msnow);
		weathermap.put("tsnow", R.drawable.tsnow);
		weathermap.put("frain", R.drawable.frost);
		weathermap.put("frost", R.drawable.frost);
		weathermap.put("duststrom", R.drawable.fog);
		weathermap.put("dblowing", R.drawable.dblowing);
		weathermap.put("cyclone", R.drawable.cyclone);
		weathermap.put("fdust", R.drawable.fdust);
		
	}

	private String phonetype = "";
	
	public String getPhoneType() {
		try {
			phonetype = android.os.Build.MODEL;
		} catch (Exception e) {
			// 获得手机型号
			phonetype = "无法获取型号";
		}
		return phonetype;
	}

	// IMEI
	private String imei = "";

	public String getImei() {
		try {
			if (imei.equals("")) {
				TelephonyManager tm = (TelephonyManager) this
						.getSystemService(Context.TELEPHONY_SERVICE);
				imei = tm.getDeviceId();
			}
		} catch (Exception e) {

		}

		return imei;
	}

	// IMSI
	private String imsi = "";

	public String getImsi() {
		try {
			if (imsi.equals("")) {

				// pad
				/*imsi = Secure.getString(this.getContentResolver(),
						Secure.ANDROID_ID);*/

				// 非pad
				// imsi = ((TelephonyManager)
				// this.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId();

				// 判断当前是否是平板设备

				if (isPad()) {
					imsi = Secure.getString(this.getContentResolver(),
							Secure.ANDROID_ID);
				} else {
					imsi = ((TelephonyManager) this
							.getSystemService(Context.TELEPHONY_SERVICE))
							.getSubscriberId();
				}

			}
		} catch (Exception e) {
			imsi = "";
			e.printStackTrace();
		}

		return imsi;
	}

	private String phone = "";

	public String getPhone() {
		try {
			if (phone.equals("")) {

				// pad
				//phone = "";

				// 手机
				// phone = ((TelephonyManager)
				// this.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();

				// 判断当前是否是平板设备

				if (isPad()) {
					phone = "";
				} else {
					phone = ((TelephonyManager) this
							.getSystemService(Context.TELEPHONY_SERVICE))
							.getLine1Number();
				}

			}
		} catch (Exception e) {
			phone = "";
			e.printStackTrace();
		}
		
		return phone;
	}

	public boolean isPad() {
		TelephonyManager tm = (TelephonyManager) this
				.getSystemService(Context.TELEPHONY_SERVICE);
		int type = tm.getPhoneType();

		// 判断当前是否是平板设备
		if (type == TelephonyManager.PHONE_TYPE_NONE) {
			return true;
		} else {
			return false;
		}
	}

	// Version
	private String version = "";

	public String getVersion() {
		if (version.equals("")) {
			try {
				PackageManager packageManager = getPackageManager();
				PackageInfo packInfo = packageManager.getPackageInfo(
						getPackageName(), 0);
				version = packInfo.versionName;
			} catch (Exception e) {
			}
		}
		return version;
	}

}
